//
//  TCLYAddressTableViewCell.m
//  YuErmuYing
//
//  Created by LYang on 16/8/27.
//  Copyright © 2016年 Tiancheng. All rights reserved.
//

#import "TCLYAddressTableViewCell.h"
#import "Macros.h"
#import "Masonry.h"


@implementation TCLYAddressTableViewCell
-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]) {
        
        self.backgroundColor = bgColor;
        
        UIView * bgView = [[UIView alloc] init];
        bgView.backgroundColor = [UIColor whiteColor];
        [self addSubview:bgView];
        [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(10);
            make.left.mas_equalTo(self);
            make.right.mas_equalTo(self);
            make.bottom.mas_equalTo(self);
        }];
        
        self.telLabel = [[UILabel alloc] init];
        self.telLabel.textColor = blackFont;
        self.telLabel.textAlignment = NSTextAlignmentCenter;
        self.telLabel.font = [UIFont systemFontOfSize:14];
        [bgView addSubview:self.telLabel];
        [self.telLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(12);
            make.right.mas_equalTo(16);
            make.width.mas_equalTo(160);
            make.height.mas_equalTo(20);
        }];
        
        self.nameLabel = [[UILabel alloc] init];
        self.nameLabel.textColor = blackFont;
        self.nameLabel.textAlignment = NSTextAlignmentLeft;
        self.nameLabel.font = [UIFont systemFontOfSize:14];
        [bgView addSubview:self.nameLabel];
        [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(12);
            make.left.mas_equalTo(12);
            make.right.mas_equalTo(self.telLabel.mas_left).offset(-10);
            make.height.mas_equalTo(20);
        }];
        
        
        self.addressLabel = [[UILabel alloc] init];
        self.addressLabel.font = [UIFont systemFontOfSize:12];
        self.addressLabel.numberOfLines = 0;
        self.addressLabel.textAlignment = NSTextAlignmentLeft;
        self.addressLabel.textColor = blackFont;
        [bgView addSubview:self.addressLabel];
        [self.addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(18);
            make.left.mas_equalTo(self.nameLabel);
            make.right.mas_equalTo(self.mas_right).offset(-12);
            make.height.mas_equalTo(30);
        }];
        
        self.addressBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.addressBtn setImage:[UIImage imageNamed:@"mineTic"] forState:UIControlStateNormal];
        [self.addressBtn setImage:[UIImage imageNamed:@"mineTick-click"] forState:UIControlStateSelected];
        [bgView addSubview:self.addressBtn];
        [self.addressBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.addressLabel.mas_bottom).offset(19);
            make.left.mas_equalTo(self.addressLabel);
            make.width.mas_equalTo(20);
            make.height.mas_equalTo(20);
        }];
        
        UILabel * address = [[UILabel alloc] init];
        address.text = @"设为默认地址";
        address.textAlignment = NSTextAlignmentCenter;
        address.font = [UIFont systemFontOfSize:12];
        address.textColor = blackFont;
        [bgView addSubview:address];
        [address mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.addressBtn.mas_right).offset(10);
            make.centerY.mas_equalTo(self.addressBtn);
            make.width.mas_equalTo(80);
            make.height.mas_equalTo(20);
        }];
        
        UILabel * delete = [[UILabel alloc] init];
        delete.text = @"删除";
        delete.textColor = blackFont;
        delete.font = [UIFont systemFontOfSize:12];
        delete.textAlignment = NSTextAlignmentCenter;
        [bgView addSubview:delete];
        [delete mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(address);
            make.right.mas_equalTo(bgView.mas_right).offset(-12);
            make.width.mas_equalTo(30);
            make.height.mas_equalTo(20);
        }];
        
        self.deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.deleteBtn setImage:[UIImage imageNamed:@"mineDelete"] forState:UIControlStateNormal];
        [bgView addSubview:self.deleteBtn];
        [self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.addressBtn);
            make.right.mas_equalTo(delete.mas_left).offset(-6);
            make.width.mas_equalTo(20);
            make.height.mas_equalTo(20);
        }];
        
        UILabel * editor = [[UILabel alloc] init];
        editor.text = @"编辑";
        editor.font = [UIFont systemFontOfSize:12];
        editor.textAlignment = NSTextAlignmentCenter;
        editor.textColor = blackFont;
        [bgView addSubview:editor];
        [editor mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(address);
            make.right.mas_equalTo(self.deleteBtn.mas_left).offset(-14);
            make.width.mas_equalTo(30);
            make.height.mas_equalTo(20);
        }];
        
        self.editorBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.editorBtn setImage:[UIImage imageNamed:@"mineEdit"] forState:UIControlStateNormal];
        [bgView addSubview:self.editorBtn];
        [self.editorBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.addressBtn);
            make.right.mas_equalTo(editor.mas_left).offset(-6);
            make.width.mas_equalTo(20);
            make.height.mas_equalTo(20);
        }];
    }
    
    return self;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
